import  {  type Request, type Response } from "express"
import { ReturnData } from "../../interface/interface"
import { CODE } from "../../utils/const"
import { getErr } from "./getSendResult"
import multer from "multer"

export const errorMiddleWare = (err: Error, req: Request, res: Response, next: Function) => {
    if(err){
        console.log(err);
        if( err instanceof multer.MulterError ){
            res.status(200).send( getErr( err.message, CODE.errorCode ) )
        }else{
            let reg = new RegExp("[\\u4E00-\\u9FFF]+","g")
            if( reg.test(err.message) ){
                res.status(200).send( getErr( err.message, CODE.errorCode ) )
            }else{
                res.status(500).send( getErr(  ) )
            }
            
        }
        
    }else{
        next()
    }
}